home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 6 / 006.d81 / pps #12 < prev    next >
Text File  |  2022-08-26  |  2KB  |  132 lines

  1.   PEEKs, POKEs, and SYSes -- Part 12
  2.  
  3.            by Jimmy Weiler
  4.  
  5.       (continued from Part 11)
  6.  
  7.  
  8.  
  9.  
  10.   You MUST move both MEMSIZ and FRETOP
  11.  
  12. at the same time.  Otherwise you will
  13.  
  14. leave some variables in your reserved
  15.  
  16. area and they will be destroyed when
  17.  
  18. you use that area for something else.
  19.  
  20.  
  21. Now... Here's how.
  22.  
  23.   To move top of BASIC down:
  24.  
  25. 10 AD=24576:rem address declaration
  26. 20 AH%=AD/256:AL%=256*(AD/256-AH%)
  27. 25 rem low and high bytes of address
  28. 30 POKE51,AL%:POKE52,AH%
  29. 35 rem move FRETOP
  30. 40 POKE55,AL%:POKE56,AH%
  31. 45 rem move MEMSIZ
  32. 50 CLR
  33. 55 rem you need to clear out all vari-
  34.   ables because you just trashed them.
  35.  
  36.  
  37. You can use this routine to move the
  38.  
  39. top of BASIC anywhere.  Just change
  40.  
  41. the address in line 10.
  42.  
  43.  
  44.   MEMSIZ stays constant as a program
  45.  
  46. runs.  FRETOP moves down as each
  47.  
  48. string variable is used.  Eventually,
  49.  
  50. enough strings may be used to cause
  51.  
  52. FRETOP to move all the way down to
  53.  
  54. the bottom of free variable space.
  55.  
  56.  
  57.  
  58.   When FRETOP collides with the bottom
  59.  
  60. of variable space, BASIC automatically
  61.  
  62. tries to move it back up to the top to
  63.  
  64. make room for more new strings.  This
  65.  
  66. process is called garbage collection.
  67.  
  68.  
  69.   Essentially, garbage collection
  70.  
  71. works by squeezing all the strings
  72.  
  73. that have not been re-assigned into
  74.  
  75. a tight mass at the top of variable
  76.  
  77. space.  Any old, obsolete, unused
  78.  
  79. string values are dropped into the bit
  80.  
  81. bucket.
  82.  
  83.  
  84.  
  85.   If you have large string arrays,
  86.  
  87. garbage collection can take several
  88.  
  89. seconds to finish.  During that time,
  90.  
  91. your Commodore will act as though the
  92.  
  93. keyboard has locked up.
  94.  
  95.  
  96.   If you have reduced the size of
  97.  
  98. BASIC memory, garbage collection will
  99.  
  100. be needed more often.
  101.  
  102.  
  103.  
  104.   Finally, to get a feel for just how
  105.  
  106. MEMSIZ and FRETOP work together, try
  107.  
  108. this program:
  109.  
  110.  
  111.  
  112. 10 FOR C = 1 to 128:B$=B$+"X":NEXT
  113. 20 MEMSIZ = PEEK(55)+PEEK(56)*256
  114. 30 FRTP = PEEK(51)+PEEK(52)*256
  115. 40 PRINT "<clr>"
  116. 50 PRINT "Top of memory = "MEMSIZ
  117. 60 PRINT "Bottom of strings = "FRTP
  118. 70 FOR C = 1 to 8:A$=B$:NEXT
  119. 80 GOTO 20
  120.  
  121.  
  122.  
  123. You should see that MEMSIZ sits firmly
  124.  
  125. in place while FRETOP falls and rises
  126.  
  127. as variables are assigned and garbage
  128.  
  129. collection happens.
  130.  
  131. ----------- End of Article -----------
  132.